#include <xscript/xtoken.h>

XTokenBoolean::XTokenBoolean(const std::wstring& flag, uint32_t line, uint32_t block):
    XToken(line, block) {
    if (flag == L"True")
        value = true;
    else
        value = false;
}

bool XTokenBoolean::getValue() const {
    return value;
}

std::wstring XTokenBoolean::getString() const {
    return value ? std::wstring(L"True") : std::wstring(L"False");
}

XToken::XToken_Enum XTokenBoolean::getTokenType() const {
    return XToken_EnumBoolean;
}

std::shared_ptr<XTokenBoolean> XTokenBoolean::asBoolean() {
    return std::dynamic_pointer_cast<XTokenBoolean>(shared_from_this());
}

XTokenInteger::XTokenInteger(const std::wstring& flag, uint32_t line, uint32_t block):
    XToken(line, block) {
    value = boost::lexical_cast<int32_t>(flag);
}

int32_t XTokenInteger::getValue() const {return value;}

std::wstring XTokenInteger::getString() const {
    return std::to_wstring(value);
}

XToken::XToken_Enum XTokenInteger::getTokenType() const {
    return XToken_EnumInteger;
}

std::shared_ptr<XTokenInteger> XTokenInteger::asInteger() {
    return std::dynamic_pointer_cast<XTokenInteger>(shared_from_this());
}

XTokenKeyword::XTokenKeyword(const std::wstring& flag, uint32_t line, uint32_t block):
    XToken(line, block) {
    if (flag == L"let")
        keywordType = XTokenKeyword_EnumLet;
    else if (flag == L"set")
        keywordType = XTokenKeyword_EnumSet;
    else
        keywordType = XTokenKeyword_EnumMax;

    value = flag;
}

std::wstring XToken::toString() const {
    std::wstringstream stream;
    stream << "module:" << getModuleName();
    stream << ",line:" << getLineNumber();
    stream << ",var:" << getString();
    return stream.str();
}
